﻿
@page
@model AdminUI.Pages.BaseData.VideoModel
@{
    var F = Html.F();
}

@section body {
    <f:HiddenField ID="GoodsID" Text="@Model.GoodsID"></f:HiddenField>
    <f:Panel ID="Panel1" BodyPadding="5" ShowBorder="false" Layout="VBox" ShowHeader="false" IsViewPort="true">
        <Items>
            <f:Grid ID="Grid1" BoxFlex="1" ShowBorder="true" ShowHeader="false" EnableTextSelection="true" EnableColumnLines="true" EnableCheckBoxSelect="false" EnableMultiSelect="false" AllowSorting="true" AllowPaging="true" IsDatabasePaging="true"
                DataIDField="VideoID" DataTextField="Title" PageSize="@ViewBag.PageSize" RecordCount="@ViewBag.Total" DataSource="@ViewBag.DataSource"
                OnSort="@Url.Handler("Grid_DoAction")" OnSortFields="Panel1" OnPageIndexChanged="@Url.Handler("Grid_DoAction")" OnPageIndexChangedFields="Panel1" OnPageIndexChangedParameter1="@(new Parameter("relationID", "F.ui.relationID.getValue()"))" OnPageIndexChangedParameter2="@(new Parameter("videoType", "F.ui.videoType.getValue()"))" FixedRowHeight="true" RowHeight="60">
                <Toolbars>
                    <f:Toolbar ID="Toolbar1" ToolbarAlign="Right" ItemSpace="1">
                        <Items>
                            <f:Button ID="btnAdd" IconAlign="Left" EnableDefaultState="false" IconFont="_Plus" Text="新增" OnClientClick="onAddClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnEdit" IconAlign="Left" EnableDefaultState="false" IconFont="_Edit" Text="编辑" OnClientClick="onEditClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnPlay" IconAlign="Left" EnableDefaultState="false" IconFont="Play" Text="播放" OnClientClick="onPlayClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnDelete" IconAlign="Left" EnableDefaultState="false" IconFont="TrashO" Text="删除" OnClientClick="onDeleteClick();"></f:Button>
                            <f:ToolbarSeparator></f:ToolbarSeparator>
                            <f:Button ID="btnRefresh" IconAlign="Left" EnableDefaultState="false" IconFont="_Refresh" Text="刷新" OnClientClick="onRefreshClick();"></f:Button>
                            <f:ToolbarFill ID="ToolbarFill1"></f:ToolbarFill>
@*                             <f:DropDownList ID="ddlCondition" SelectedValue="" Width="150" Hidden="@Model.VideoType > 0">
                                <f:ListItem Text="== 请选择条件 ==" Value="" />
                                <f:ListItem Text="关联对象ID" Value="RelationID" />
                                <f:ListItem Text="视频标题" Value="Title" />
                            </f:DropDownList>
                            <f:TriggerBox ID="ttbSearch" ShowLabel="false" EmptyText="请输入搜索关键字" TriggerIcon="Search" OnTriggerClick="@Url.Handler("Grid_DoAction")" OnTriggerClickFields="Panel1" Hidden="@Model.VideoType > 0"
                                          OnTriggerClickParameter1="@(new Parameter("actionType", "search", ParameterMode.String))"
                                          OnTriggerClickParameter2="@(new Parameter("searchText", "F.ui.ttbSearch.getValue()"))"
                                          OnTriggerClickParameter3="@(new Parameter("searchCondition", "F.ui.ddlCondition.getValue()"))">
                            </f:TriggerBox> *@
                        </Items>
                    </f:Toolbar>
                </Toolbars>
                <Columns>
                    <f:RowNumberField HeaderText="#" TextAlign="Center" />
                    <f:RenderField HeaderText="视频ID" DataField="VideoID" FieldType="Int" Hidden="true" Width="120" TextAlign="Center" />
                    <f:RenderField HeaderText="封面" DataField="CoverUrl" RendererFunction="renderImage" Width="80" TextAlign="Center" />
                    @* <f:RenderField HeaderText="商品ID" DataField="GoodsID" FieldType="Int" Width="120" TextAlign="Center" /> *@
                    <f:RenderField HeaderText="大小" DataField="FileSize" FieldType="Int" Width="80" TextAlign="Right" />
                    <f:RenderField HeaderText="排序" DataField="SortFlag" FieldType="Int" Width="80" TextAlign="Center" />
                    <f:RenderField HeaderText="备注" DataField="Memo" Width="200" ExpandUnusedSpace="true" />
                </Columns>
                <PageItems>
                    <f:ToolbarSeparator></f:ToolbarSeparator>
                    <f:ToolbarText Text="每页记录数："></f:ToolbarText>
                    <f:DropDownList ID="ddlGridPageSize" Width="60" SelectedValue="@ViewBag.PageSize" OnSelectedIndexChanged="@Url.Handler("Grid_DoAction")" 
                            OnSelectedIndexChangedParameter1="@(new Parameter("actionType","changePageSize",ParameterMode.String))"
                            OnSelectedIndexChangedParameter2="@(new Parameter("relationID", "F.ui.relationID.getValue()"))" 
                            OnSelectedIndexChangedParameter3="@(new Parameter("videoType", "F.ui.videoType.getValue()"))"
                            OnSelectedIndexChangedFields="Panel1">
                        <Items>
                            <f:ListItem Text="10" Value="10"></f:ListItem>
                            <f:ListItem Text="20" Value="20"></f:ListItem>
                            <f:ListItem Text="30" Value="30"></f:ListItem>
                            <f:ListItem Text="50" Value="50"></f:ListItem>
                            <f:ListItem Text="100" Value="100"></f:ListItem>
                            <f:ListItem Text="200" Value="200"></f:ListItem>
                        </Items>
                    </f:DropDownList>
                </PageItems>
            </f:Grid>
        </Items>
    </f:Panel>

    <f:Window ID="Window1" IsModal="true" Hidden="true" Target="Top" EnableResize="true" EnableMaximize="true" EnableIFrame="true" Width="700" Height="500">
        @*<Listeners>
                <f:Listener Event="close" Handler="onWindowClose('refresh');"></f:Listener>
            </Listeners>*@
    </f:Window>
}

@section script {
    <script src="~/res/js/grid.js"></script>
    <script>
        function onAddClick(event) {
            var path = "/BaseData/VideoAdd?rid=@Model.GoodsID";
            F.ui.Window1.show(path, '新增商品视频');
        }

        function onEditClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要修改的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/VideoEdit?id=" + selectedRow;
            F.ui.Window1.show(path, '编辑商品视频');
        }

        function onPlayClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要播放的记录！');
                return;
            }

            var selectedRow = grid1.getSelectedRow();
            var path = "/BaseData/VideoPreview?vid=" + selectedRow;
            F.ui.Window1.show(path, '播放视频', 640, 480);
        }

        function onDeleteClick(event) {
            var grid1 = F.ui.Grid1;
            if (!grid1.hasSelection()) {
                showNotify('请选择要删除的记录！');
                return;
            }

            var selectedRows = grid1.getSelectedRows();
            F.confirm({
                message: '确定要删除所选记录吗？',
                target: '_top',
                ok: function () {
                    F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                        goodsID: @Model.GoodsID,
                        actionType: 'delete',
                        selectedIDs: selectedRows
                    });
                }
            });
        }
        function onRefreshClick() {
            var grid1 = F.ui.Grid1;
            var selectedRows = grid1.getSelectedRows();
            F.doPostBack('@Url.Handler("Grid_DoAction")', 'Panel1', {
                goodsID: @Model.GoodsID,
                actionType: 'refresh',
                selectedIDs: selectedRows
            });
        }

        //HTML格式化
        function renderIconClass(value, params) {
            return F.formatString('<i class="f-icon {0}" title="{0}"></i>', value);
        }

        //图片预览
        function renderImage(value, params) {
            //return '<a href="javascript:;" class="imagePreview">预览</a>'; //文字链接
            //return '<a href="javascript:;" title="预览图片" class="imagePreview"><i class="f-icon f-icon-image f-grid-cell-iconfont"></i></a>';//图片字体按钮
            return '<a href="javascript:;" class="imagePreview"><img style="width:58px;height:45px;margin:0,auto;" src="' + value + '"/></a>';//自定义图片按钮
            //return '<a href="javascript:;" class="imagePreview"><img class="f-grid-cell-icon" src="@Url.Content("~/res/icon/pencil.png")"></a>';//自定义图片按钮
        }

        F.ready(function () {
            //var grid = F.ui.Grid1;

            ////注册图片预览单击事件
            //grid.el.on('click', 'a.imagePreview', function (event) {
            //    var rowEl = $(this).closest('.f-grid-row');
            //    var rowData = grid.getRowData(rowEl);

            //    var path = "/Dialog/ImagePreview?url=" + rowData.values.ImageUrl;
            //    F.ui.Window1.show(path, '图片预览', 800, 800);
            //});

            var preview = new Preview({
                imgWrap: 'Grid1' // 指定该容器里的图片点击预览
            })
        });

    </script>
    <script src="~/res/third-party/jspciyl/preview.js"></script>
}

@section head{
    <link rel="stylesheet" type="text/css" href="~/res/third-party/jspciyl/preview.css" />
    <style>
        .f-grid-cell.f-grid-cell-Title .f-grid-cell-inner {
            white-space: normal;
            word-break: break-all;
        }

        .f-grid-cell.f-grid-cell-Memo .f-grid-cell-inner {
            white-space: normal;
            word-break: break-all;
        }
    </style>
}

